from myelin.Ns import MYELINS

from Ft.Rdf.Parsers.Versa.Serializers import AmaraVrx

from Commit import Form


class Form(Form):
    
    newSerializer = AmaraVrx.Serializer
    
    def createInstance(self, context, node):
        eventData = context.event.data
        map = context.uriMapper.apply
        
        model = context.model
        params = eventData.params
        results = eventData.results
        
        nxa = node.xml_append
        nxc = node.xml_create_element
        
        super(Form,self).createInstance(
            context,
            nxa(
                nxc(
                    u'a:search-params', MYELINS
                )
            )
        )
        
        curNode = nxa(
            nxc(
                u'a:search-results', MYELINS,
            )
        )
        
        s = self.newSerializer(results)
        s.serialize(
            curNode
        )        
        
        curNode.xml_set_attribute(u'mime-type', unicode(s.imt))
        if s.isXml: 
            curNode.xml_set_attribute(u'xml', u'1')
        
        return node